/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Request, Response } from 'express';
import { ResponseItem, responseRandom } from './utils';
import Mock from 'mockjs';

Mock.Random.extend({
  phone: function () {
    const prefixs = ['132', '134', '150'];
    return this.pick(prefixs) + Mock.mock(/\d{8}/);
  },
});

export default {
  // 微快递会员列表
  'POST /wkd/MemberCard/lists': (req: Request, res: Response) => {
    const { mobile } = req.body;
    const list: WkdVipMange.ListItem[] = Array.from({ length: 20 }).map((_, index) => {
      return Mock.mock({
        user_id: '@id',
        kb_id: '@id',
        'card_id|1': ['1', '2', '3'],
        username: '@phone',
        expires_time: '@date',
        'status|1': ['0', '1', '2'],
        total_profit: '1',
        share_num: '2',
        channel: '2',
        'channel|1': ['mina', 'aliapp'],
      });
    });

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: mobile ? list : [],
    };
    return res.json(result);
  },
  // 微快递会员操作记录列表
  'POST /wkd/MemberCard/openMemberCardRecord': (req: Request, res: Response) => {
    let data = Mock.mock({
      'data|30': [
        {
          user_id: '@id',
          kb_id: '@id',
          'card_id|1': ['1', '2', '3'],
          username: '@phone',
          adm_name: '@phone',
          'channel|1': ['mina', 'aliapp'],
          remarks: '订单投诉，免费开通一个月',
          create_time: '@date',
          operate_time: '@date',
        },
      ],
      total: 30,
    });

    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: data,
    };
    return res.json(result);
  },

  // 微快递会员，退款信息
  'POST /wkd/MemberCard/refundOpenMemberCardRecord': (req: Request, res: Response) => {
    const result: ResponseItem = {
      ...Mock.mock({
        code: 0,
        msg: '成功',
        'data|3': [
          {
            id: '@id',
            user_id: '@id',
            open_id: '@id',
            kb_id: '@id',
            'card_id|1': ['1', '2', '3'],
            price: '1',
            duration: '1',
            create_time: '@date',
            update_time: '@date',
            status: '@date',
            'channel|1': ['mina', 'aliapp'],
            trade_number: '@phone',
            type: '@phone',
            adm_id: '@id',
            adm_name: '@phone',
            remarks: '订单投诉，免费开通一个月',
            operate_time: '@date',
            refund_status: '@date',
            refund_time: '@date',
            start_time: '@date',
            expires_time: '@date',
            username: '@phone',
          },
        ],
        total: 3,
      }),
    };
    return res.json(result);
  },

  // 获取会员卡配置
  'POST /wkd/MemberCard/getConfigList': (req: Request, res: Response) => {
    const result: ResponseItem = {
      code: 0,
      msg: '成功',
      data: [
        {
          id: '1',
          name: '月卡',
          nickname: '优享',
          duration: '31',
          price: '5.10',
          original_cost: '5.80',
          create_time: '2021-11-16 10:59:02',
          update_time: '2021-11-16 10:59:02',
        },
        {
          id: '2',
          name: '季卡',
          nickname: '尊享',
          duration: '93',
          price: '17.40',
          original_cost: '15.80',
          create_time: '2021-11-16 10:59:37',
          update_time: '2021-11-16 10:59:37',
        },
        {
          id: '3',
          name: '年卡',
          nickname: '王者',
          duration: '127',
          price: '69.60',
          original_cost: '48.80',
          create_time: '2021-11-16 11:00:14',
          update_time: '2021-11-16 11:00:14',
        },
      ],
    };
    return res.json(result);
  },

  // 开通操作
  'POST /wkd/MemberCard/openMemberCard': (req: Request, res: Response) =>
    responseRandom(req, res, {}),
};
